<template>
  <div class="container-body">
    <!--header头部-->
    <el-row :gutter="20">
      <el-col :span="24">
        <p-header></p-header>
      </el-col>
    </el-row>

    <!--查看指标变化情况的入口按钮-->
    <div @click="openChangeView" class="showchange-btn">
      <i class="el-icon-search"></i>
      指标变化分析
      <i style="margin-top: 2px;" class="el-icon-d-arrow-right"></i>
    </div>

    <transition name="cv-popup">
      <!--指标变化情况抽屉栏-->
      <c-view
        :filters="filters"
        :changeTitle="changeTitle"
        :computeData="computeData"
        v-show="cv_side"
        class="cv-pop-up"
        ref="drawer"
        @cvCloseEvent="cvCloseEvent"
        @bodyClick="cvClose"
        @touchmove.stop.prevent>
      </c-view>
    </transition>

    <transition v-if="lv_side" name="lv-popup">
      <!-- 标签情况抽屉栏 -->
      <l-view
        :checkedNodes="checkedNodes"
        :active="active"
        :isDisabled="isDisabled"
        :inputText="inputText"
        :groupText="groupText"
        :tree_checked_keys="tree_checked_keys"
        :treeData="treeArr"
        @lvNextStepEvent="lvNextStepEvent"
        @lvLastStepEvent="lvLastStepEvent"
        @lgInputChange="lgInputChange"
        @lvCloseEvent="lvCloseEvent"
        @lvOnTreeSelected="lvOnTreeSelected"
        v-show="lv_side"
        class="lv-pop-up"
        @bodyClick="lvClose"
        @touchmove.stop.prevent
        @submitData="doSubmitData"
      ></l-view>
    </transition>

    <el-form label-width="100px" label-position="top">
      <el-row :gutter="20">
        <el-col :span="10" :push="1">
          <el-form-item label="公司名称" prop="name">
            <el-select size="small" v-model="initCompanyVal" placeholder="请选择公司名称" @change="onCompanySelected">
              <el-option
                v-for="item in companyArr"
                :key="item.id"
                :label="item.name"
                :value="item.name">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="10" :push="3">
          <el-form-item label="业绩报类型" prop="region">
            <el-select size="small" v-model="initTypeVal" placeholder="请选择业绩报类型" @change="onTypeSelected">
              <el-option
                v-for="item in typeArr"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="10" :push="1">
          <el-form-item label="报表年份" prop="name">
            <el-select size="small" v-model="initYearVal" placeholder="请选择报表年份" @change="onYearSelected">
              <el-option
                v-for="item in yearArr"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="10" :push="3">
          <el-form-item label="生成份数" prop="name">
            <el-select size="small" v-model="initNumberVal" placeholder="请选择生成份数" @change="onNumSelected">
              <el-option
                v-for="item in numberArr"
                :key="item.id"
                :label="item.name"
                :value="item.name">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="16">
        <!--标签组-->
        <el-col :span="10" :push="1">
          <div class="label-group-title">标签组
            <div style="float: right">
              <div @click="openLabelView" :class="divDisable==true? 'no-click-event':'yes-click-event'"
                   style="display: inline;cursor: pointer;">
                <i class="el-icon-plus"/>
                新标签组
              </div>
            </div>
          </div>

          <div class="div_label" style="margin-top:9px;">
            <el-radio-group @change="onRadioSelected" v-model="initRadioVal">
              <el-radio
                v-for="(item,index) in groupArr"
                class="radio-style"
                :label="item.name"
                @mouseenter.native="enter(index)"
                @mouseleave.native="leave">
                <span>{{item.name}}</span>
                <el-tooltip placement="top" content="删除" :getPopupContainer="getPopupContainer">
                  <i
                    v-if="isClose == index"
                    @click.stop="deleteGroup(item.name)"
                    class="el-icon-circle-close-outline"
                    style="margin-left: 5px"
                  />
                </el-tooltip>
                <el-tooltip placement="top" content="编辑" :getPopupContainer="getPopupContainer">
                  <i
                    v-if="isClose == index && radioValue == item.name"
                    @click="openAndEditLabelView(item.name)"
                    class="el-icon-edit-outline"
                    style="margin-left: 5px"
                  />

                </el-tooltip>
              </el-radio>
            </el-radio-group>
          </div>
        </el-col>
        <!--已选标签-->
        <el-col :span="10" :push="3">
          <div class="label-group-title" title="">已选标签
            <div class="div_label" style="margin-top:9px;">
              <div style="height: 100%;"
                   v-loading="loading2"
                   element-loading-spinner="el-icon-loading"
                   element-loading-background="rgba(0, 0, 0, 0)">
                <el-tree
                  :data="treeArr"
                  :show-checkbox="false"
                  default-expand-all
                  node-key="key"
                  ref="trees"
                  :props="defaultProps"
                  style="color: white;background-color: rgba(128,0,128,0);"
                  @check="onTreeSelected"
                  :default-checked-keys="tree_checked_keys"
                  :filter-node-method="filterNode"
                  :render-content="renderContent"
                ></el-tree>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>

    </el-form>


    <!--按钮-->
    <el-row :gutter="24">
      <el-col :span="24" style="text-align: center;margin: 20px auto;">
        <el-button type="primary" @click="validate">生成点评报</el-button>
      </el-col>
    </el-row>

  </div>

</template>

<script>
import axios from "axios";
import Header from '../../components/common/header';
import {Card, Button, Table, Input, Tree, Row, Col, Select, Form, Radio, Tag, Tooltip} from 'element-ui';
import ChangeView from "../components/changeview/ChangeView";
import LabelView from "../components/labelview/LabelView";


let id = 1000;
var self = null;

/**
 *  获取"增加"的数量
 */
const getUpNum = (arr) => {
  let num = 0;
  for (let i in arr) {
    if (arr[i].trendency == '增加') {
      num++;
    }
  }
  return num;
};

/**
 *  获取"减少"的数量
 */
const getDownNum = (arr) => {
  let num = 0;
  for (let i in arr) {
    if (arr[i].trendency == '减少') {
      num++;
    }
  }
  return num;
};

/**
 * 参数设置页面
 */
export default {
  name: "setting",
  components: {
    cView: ChangeView,
    lView: LabelView,
    pHeader: Header,
    elCard: Card,
    elButton: Button,
    elTable: Table,
    elInput: Input,
    elTree: Tree,
    elRow: Row,
    elCol: Col,
    elSelect: Select,
    elForm: Form,
    elRadio: Radio,
    elTag: Tag,
    elTooltip: Tooltip
  },
  data() {
    return {
      divDisable: false,
      isDebug: false, //
      initCompanyVal: "中国平安",  //"公司名称"下拉选择默认值
      initTypeVal: "4", //"业绩报类型"下拉选择默认值
      initYearVal: "2017年", //"报表年份"下拉选择默认值
      initNumberVal: 3,  //"生成份数"下拉选择默认值
      initRadioVal: null, //标签组默认当前选中
      companyArr: [
        {
          id: 0,
          name: "中国平安"
        },
        {
          id: 1,
          name: "中国人寿"
        },
        {
          id: 2,
          name: "中国太保"
        },
        {
          id: 3,
          name: "新华保险"
        }
      ],
      typeArr: [
        {
          id: "1",
          name: "一季度"
        },
        {
          id: "2",
          name: "半年报"
        },
        {
          id: "3",
          name: "三季度"
        },
        {
          id: "4",
          name: "年报"
        }
      ],
      yearArr: [
        {
          id: 1,
          name: "2016年"
        },
        {
          id: 2,
          name: "2017年"
        },
        {
          id: 3,
          name: "2018年"
        }
      ],
      numberArr: [
        {
          id: 1,
          name: 1
        },
        {
          id: 3,
          name: 3
        },
        {
          id: 5,
          name: 5
        },
        {
          id: 10,
          name: 10
        }
      ],
      groupArr: [], //标签组
      curren_groupText_odname: null, //当前标签组名
      radioValue: null, //单选框选中的值
      isClose: null, //是否显示标签组单选框的删除小按钮
      cv_side: false, //变化抽屉控制器
      lv_side: false, //标签抽屉控制器
      allLabelParam: {},  //获取当前公司的标签的全部标签
      groupParam: {}, //获取标签组参数
      labelGroupParam: {}, //获取标签组标签参数
      tagArr: [], //标签
      treeArr: [],  //标签树-新增或编辑
      tree_checked_keys: [],  //默认选中的树节点id
      tree_checked_label: [],  //默认选中的树节点名称
      tags: [],  //已选中的树标签节点名称
      checkedNodes: [],  //已选中的树节点名称
      commonParam: {},  //公共参数
      requestData: {},
      actionType: 0,  //标签组drawer类型 0:新增 1:编辑
      historyRadioObj: {}, //历史单选框选中的标签组
      defaultRadioName: "", //默认单选中的数值
      lastRadioSelectObj: {},  //单选框最后一次选中的数据
      groupTitle: null,
      inputText: '',//默认的输入框内容
      currentInputText: null,
      isDisabled: true,  //下一步按钮是否可用
      active: '0', //用来判断是否下一步 '0':上一步;'1':下一步
      changeTitle: null, //指标变化标题
      computeData: [], //指标对比数据
      filters: [], //指标对比数据过滤数据格式
      defaultProps: {
        children: 'children',
        label: 'name',
        key: 'key'
      },
      loading2: false,
      get_year_url: '',
      newGroupText: null
    };
  },
  computed: {},
  // 初始化数据
  created() {
    self = this;
    self.initData();
  },
  updated() {
    self.$refs.trees.filter();
  },
  methods: {
    //  初始化
    initData() {
      let historyParam = JSON.parse(sessionStorage.getItem("historyParam"));
      let year = self.$clearStr("年", self.initYearVal, "");
      self.changeTitle = self.initCompanyVal;
      let initParam = {
        company: self.initCompanyVal,
        type: self.initTypeVal,
        year: year,
        number: self.initNumberVal
      };
      if (historyParam) {
        self.commonParam = historyParam;
        self.initCompanyVal = historyParam.company;  //公司
        if (historyParam.type == "1") {       //类型
          self.initTypeVal = "一季度";
        } else if (historyParam.type == "2") {
          self.initTypeVal = "半年报";
        } else if (historyParam.type == "3") {
          self.initTypeVal = "三季度";
        } else {
          self.initTypeVal = "年报";
        }
        self.initYearVal = historyParam.year + "年"; //年份
        self.initNumberVal = historyParam.number;  //份数
      } else {
        self.initCompanyVal = initParam.company;
        self.commonParam = initParam;
      }

      self.allLabelParam = {
        company: self.commonParam.company,
        year: year,
        type: self.commonParam.type
      };

      self.requestData = {
        company: self.commonParam.company,
        year: self.commonParam.year,
        type: self.commonParam.type
      };
      console.log("初始化的数据：", self.commonParam);
      self.groupParam = {
        company: self.commonParam.company,
        group_name: null,
      };
      self.getGroupReq(self.groupParam);
      self.getAllLabelReq(self.allLabelParam);
    },

    //  获取标签组
    getGroupReq(param) {
      console.log("getGroup()", param);
      let mess = null;
      axios.get(self.$URLOBJ.GETGROUPURL, {params: param}).then(res => {
        if (res.data.respcode != 0) {
          mess = res.data.respmesg;
          self.$errorMessage(mess);
          return;
        }

        if (res.data.results.length > 0) {
          self.groupArr = res.data.results;
          var name = null;
          console.log("之前点击的单选项", self.historyRadioObj.name);
          if (self.historyRadioObj.name) {
            console.log("1")
            name = self.historyRadioObj.name;
          } else if (sessionStorage.getItem("historyRadioName")) {
            console.log("2");
            name = sessionStorage.getItem("historyRadioName");
            self.historyRadioObj.name = name;
          } else {
            console.log("3")
            name = res.data.results[0].name;
            self.defaultRadioName = name;
          }
          self.lastRadioSelectObj.groupText = name;
          self.initRadioVal = name;
          console.log("之前点击的单选项", self.initRadioVal);
          self.radioValue = name;
          self.labelGroupParam = {
            company: self.commonParam.company,
            group_name: name
          };
          self.getGroupLabel(self.labelGroupParam);
        } else {
          self.groupArr = [];
          self.tagArr = [];
          self.tree_checked_keys = [];
          self.radioValue = null;
        }
      })
        .catch(err => {
          self.$errorMessage(err.message);
          console.log("获取标签组-网络请求异常：", err.message);
        });
    },
    //  获取标签组下的标签
    getGroupLabel(param) {
      console.log("getGroupLabel()", param);
      let mess = null;
      let labelSelected = [];
      if (self.isDebug) {
        labelSelected = [{"id": 2, "label": "业绩综述-财务业绩"}];
        self.tree_checked_keys = self.$getDefaultCheckedKeys(labelSelected);
      }
      {
        axios.get(self.$URLOBJ.GETGROUPURL, {params: param}).then(res => {
          self.divDisable = false;
          if (res.data.respcode != 0) {
            mess = res.data.respmesg;
            self.$errorMessage(mess);
            return;
          }
          // labelSelected = res.data.results[0].labels;
          labelSelected = res.data.results[0].keys;
          console.log(labelSelected);
          self.tree_checked_keys = self.$getDefaultCheckedKeys(labelSelected);
          console.log('选中的标签zhangxf', self.tree_checked_keys);
          self.tagArr = labelSelected;
          self.lastRadioSelectObj.label = labelSelected;

          let arr = [];
          for (let i in labelSelected) {
            arr.push(labelSelected[i].label);
          }
          self.tree_checked_keys = arr;


          self.checkedNodes = res.data.results[0].nodes;
          self.$compute_next_step(self.checkedNodes, self.treeArr);
          console.log('选中的标签 checkedNodes', self.checkedNodes);
        })
          .catch(err => {
            self.$errorMessage(err.message);
            console.log("获取标签组详细-网络请求异常：", err.message);
            self.divDisable = false;
          });
      }

    },
    //  删除标签组
    deleteGroupReq(param) {
      console.log("deleteGroupReq()", param)
      let mess = null;
      axios.get(self.$URLOBJ.DELGROUPURL, {params: param}).then(res => {
        if (res.data.respcode != 0) {
          mess = res.data.respmesg;
          self.$errorMessage(mess);
          return;
        }
        self.groupParam = {
          company: self.commonParam.company,
          group_name: null,
        };
        self.getGroupReq(self.groupParam);
      })
        .catch(err => {
          self.$errorMessage(err.message);
          console.log("删除标签组-网络请求异常：", err.message);
        });
    },
    //  增加标签组
    addGroupReq(param) {
      console.log("addGroupReq()", param);
      let mess = null;
      axios.get(self.$URLOBJ.ADDGROUPURL, {params: param}).then(res => {
        if (res.data.respcode != 0) {
          mess = res.data.respmesg;
          self.$errorMessage(mess);
          return;
        }
        self.lv_side = false;
        self.groupParam = {
          company: self.commonParam.company,
          group_name: null,
        }
        self.getGroupReq(self.groupParam);
      })
        .catch(err => {
          self.$errorMessage(err.message);
          console.log("增加标签组-网络请求异常：", err.message);
        });
    },
    //  修改标签组
    updateGroupReq(param) {
      console.log("updateGroupReq()", param);
      let mess = null;
      axios.get(self.$URLOBJ.UPDATEGROUPURL, {params: param}).then(res => {
        if (res.data.respcode != 0) {
          mess = res.data.respmesg;
          self.$errorMessage(mess);
          return;
        }
        self.groupParam = {
          company: self.commonParam.company,
          group_name: null,
        }
        self.getGroupReq(self.groupParam);
        self.lv_side = false;
      })
        .catch(err => {
          self.$errorMessage(err.message);
          console.log("修改标签组-网络请求异常：", err.message);
        });
    },
    //  获取标签数据
    getAllLabelReq(param) {
      console.log("getAllLabelReq()", param);
      self.loading2 = true;
      let treeArr = [];
      let mess = null;
      if (
        param.company &&
        param.year &&
        param.type
      ) {
        axios
          .get(self.$URLOBJ.GETRECORD2URL, {
            params: param
          })
          .then(res => {
            if (res.data.respcode != 0) {
              mess = res.data.respmesg;
              self.$errorMessage(mess);
              self.loading2 = false;
              return;
            }
            treeArr = res.data.result;
            if (treeArr) {
              self.$traverse_tree1(treeArr);
              self.setArrLabelEmotion(treeArr);
              self.treeArr = treeArr;
              if (self.actionType == 1) {
                console.log(">>>>>>>", self.checkedNodes);
                self.$compute_next_step(self.checkedNodes, self.treeArr);
                console.log("编辑获取标签数据后遍历树后的数据", self.treeArr);
              } else {
                console.log("新增获取标签数据后遍历树后的数据", self.treeArr);
              }
              // self.$refs.trees.filter();
            }
            self.loading2 = false;
          })
          .catch(err => {
            self.$errorMessage(err.message);
            console.log("获取全部标签数据-网络请求异常：", err.message);
            self.loading2 = false;
          });
      }
    },
    //  获取指标对比数据
    getComputeReq(paramData) {
      console.log("getComputeReq()", paramData);
      let mess = null;
      if (
        paramData.company &&
        paramData.year &&
        paramData.type
      ) {
        axios
          .get(self.$URLOBJ.COMPUTEURL, {
            params: paramData
          })
          .then(res => {
            if (res.data.respcode != 0) {
              mess = res.data.respmesg;
              self.$errorMessage(mess);
              return;
            }
            self.computeData = res.data.results.history;
            getUpNum(self.computeData);
            getDownNum(self.computeData);
            self.filters = [{
              text: '增加(' + getUpNum(self.computeData) + ')',
              value: '增加'
            }, {text: '减少(' + getDownNum(self.computeData) + ')', value: '减少'}]
          })
          .catch(err => {
            self.$errorMessage(err.message);
            console.log("获取指标对比数据-网络请求异常：", err.message);
          });
      } else {
        mess = "请完成配置参数后再请求网络";
        self.$errorMessage(mess);
      }
    },
    //  获取年份
    getYearReq(param) {
      console.log("getYearReq()", param);
      var mess = null;
      axios.get(self.get_year_url, {params: param}).then(res => {
        if (res.data.respcode != 0) {
          mess = res.data.respmesg;
          self.$errorMessage(mess);
          return;
        }
        ;
        self.yearArr = res.data.results;
      })
        .catch(err => {
          self.$errorMessage(err.message);
          console.log("获取标签组-网络请求异常：", err.message);
        });
    },

    //  公司名称选择
    onCompanySelected(val) {
      console.log(`onCompanySelected(): ${val}`);
      let company = val;
      self.allLabelParam.company = company;
      self.tagArr = [];
      self.tree_checked_keys = [];
      self.changeTitle = company;
      self.requestData.company = val;
      self.commonParam.company = val;
      self.groupParam = {
        company: self.commonParam.company,
        group_name: null,
      }
      self.labelGroupParam = null;
      self.initRadioVal = null;
      self.historyRadioObj = {};
      self.groupArr = [];
      self.treeArr = null;
      self.radioValue = null;
      sessionStorage.removeItem("historyRadioName");
      self.getGroupReq(self.groupParam);
      self.getAllLabelReq(self.allLabelParam);
    },
    //  业绩报类型选择
    onTypeSelected(val) {
      console.log(`onTypeSelected(): ${val}`);
      let type = val;
      self.allLabelParam.type = type;
      self.requestData.type = val;
      self.commonParam.type = val;
    },
    //  报表年份选择
    onYearSelected(val) {
      val = self.$clearStr("年", val, "")
      console.log(`onYearSelected(): ${val}`);
      let year = val;
      self.allLabelParam.year = year;
      self.requestData.year = val;
      self.commonParam.year = val;
    },
    //  生成份数选择
    onNumSelected(val) {
      console.log(`onNumSelected(): ${val}`)
      self.commonParam.number = val;
    },

    //  标签单选框选择
    onRadioSelected(val) {
      console.log(`onRadioSelected():${val}`);
      self.lastRadioSelectObj.groupText = val;
      self.radioValue = val;
      self.historyRadioObj = {
        name: val
      };
      var name = val;  //标签组名称
      self.labelGroupParam = {
        company: self.commonParam.company,
        group_name: name
      };
      self.getGroupLabel(self.labelGroupParam)
    },
    //  打开标签抽屉
    openLabelView() {
      self.$nextTick(() => {
        self.active = '0';
        self.actionType = 0;
        self.tree_checked_keys = [];
        self.groupText = "新增标签组";
        self.inputText = '';
        self.checkedNodes = [];
        self.curren_groupText_odname = null;
        self.getAllLabelReq(self.allLabelParam);
        self.$nextTick(() => {
          self.lv_side = true;
        })
        self.divDisable = true;
      })
    },
    //  鼠标经过
    enter(index) {
      if (self.groupArr[index].type == 1) {  //自定义
        self.isClose = index;
      } else {  //内置
        self.isClose = -1;
      }
    },
    //  鼠标离开
    leave() {
      self.isClose = -1;
    },
    //  打开并编辑标签抽屉
    openAndEditLabelView(val) {
      self.active = '0';
      self.curren_groupText_odname = val;
      self.actionType = 1;
      let groups = self.lastRadioSelectObj;
      self.lastRadioSelectObj.groupText = val;
      self.groupText = "编辑标签组\"" + val + "\"";
      self.inputText = val;
      console.log("点击编辑的单选框", val);
      console.log("最后一次单选框选中的数据", groups);
      if (groups.groupText == val) {
        let arr = [];
        for (let i in groups.label) {
          arr.push(groups.label[i].label);
        }
        self.tree_checked_keys = arr;
      } else {
        self.tree_checked_keys = [];
      }
      // self.checkedNodes = self.tree_checked_keys;
      console.log("openAndEditLabelView后", self.tree_checked_keys);
      self.getAllLabelReq(self.allLabelParam);
      self.currentInputText = val;
      self.$nextTick(() => {
        self.lv_side = true;
      });
      self.isDisabled = false;

    },
    //  点击删除选中的标签组
    deleteGroup(name) {
      var param = {company: self.commonParam.company, group_name: name}
      self.deleteGroupReq(param);
      self.historyRadioObj = {};
      sessionStorage.removeItem("historyRadioName");
    },
    //  浮层渲染父节点，默认渲染到 body 上
    getPopupContainer(trigger) {
      return trigger.parentElement;
    },

    //  已选标签渲染
    renderContent(h, {node, data, store}) {
      return h('span',
        {
          'class': {
            // 'green': !node.emotion || (node.emotion && node.emotion === 0),
            'red': node.emotion && node.emotion === 1
          },
          style: {
            'flex': 1,
            'display': 'flex',
            'align-items': 'center',
            'justify-content': 'space-between',
            'font-size': '14px',
            'padding-right': '8px'
          },
        }, [
          h('span', node.label),
          h('span')
        ])
    },
    //  已选标签选择
    onTreeSelected(checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys) {
      console.log('OnTreeSelected', checkedKeys);
      let tagsArr = [];
      let checkedNodesArr = checkedKeys.checkedNodes;
      console.log("onTreeSelected 选中的节点", checkedNodesArr);
      self.$compute_next_step(checkedNodesArr, self.treeArr);
      if (checkedNodesArr) {
        for (let i in checkedNodesArr) {
          tagsArr.push({
            id: checkedNodesArr[i].id,
            name: checkedNodesArr[i].key
          })
        }
      }
      self.tags = tagsArr;
      checkedNodesArr = self.$getDefaultCheckedKeys(tagsArr);
      self.checkedNodes = checkedNodesArr;
      //编辑
      var name = self.initRadioVal;
      let updateParam = {
        new_group_name: name,
        old_group_name: name,
        company: self.commonParam.company,
        labels: JSON.stringify(self.$genResult(self.treeArr))
      }
      self.updateGroupReq(updateParam);
    },
    //  已选标签过滤节点
    filterNode(value, data, node) {
      if (data.is_select) {
        return true;
      } else {
        return false;
      }
    },

    //  设置所有的标签的情绪导向默认都是正面
    setArrLabelEmotion(arr) {
      if (Array.isArray(arr) && arr && arr.length > 0) {
        for (let i in arr) {
          arr[i].emotion = 0; //默认正面
          if (Array.isArray(arr[i].children) && arr[i].children && arr[i].children.length > 0) {
            self.setArrLabelEmotion(arr[i].children);
          }
        }
      }
    },
    //  标签组输入框的value变化监听
    lgInputChange(val) {
      console.log('lvlgInputChange', val);
      self.currentInputText = val;
      let isDisabled = true;
      console.log("》》》》》actionType", JSON.stringify(self.checkedNodes) != '[]');
      if (self.actionType == 0) {
        if (self.curren_groupText_odname != self.currentInputText
          && JSON.stringify(self.checkedNodes) != '[]') {
          isDisabled = false;
        }
      } else {
        isDisabled = false;
      }

      self.isDisabled = isDisabled;

      self.inputText = val;
    },
    //  标签抽屉树选中事件监听
    lvOnTreeSelected(checkedKeys) {
      console.log('lvOnTreeSelected', checkedKeys);
      let tagsArr = [];
      let checkedNodesArr = checkedKeys.checkedNodes;
      console.log("已选中的节点", JSON.stringify(checkedNodesArr));
      self.$compute_next_step(checkedNodesArr, self.treeArr);
      console.log("====", self.treeArr);
      // setShowTreeNode(self.treeArr);
      if (checkedNodesArr) {
        for (let i in checkedNodesArr) {
          tagsArr.push({
            id: checkedNodesArr[i].id,
            name: checkedNodesArr[i].key
          })
        }
      }
      self.tags = tagsArr;
      checkedNodesArr = self.$getDefaultCheckedKeys(tagsArr);
      self.checkedNodes = checkedNodesArr;
      let isDisabled = true;

      if (self.actionType == 0) { //新增
        if (!self.currentInputText || JSON.stringify(self.checkedNodes) == '[]') {
          isDisabled = true;
        } else {
          isDisabled = false;
        }
      } else {  //编辑
        console.log(self.currentInputText);
        console.log(!self.currentInputText);
        console.log(JSON.stringify(self.checkedNodes) == '[]');
        if (!self.currentInputText || JSON.stringify(self.checkedNodes) == '[]') {
          console.log("zhangxfzhangxfzhangxfzhangxf");
          isDisabled = true;
        } else {
          if (self.currentInputText != self.lastRadioSelectObj.groupText || JSON.stringify(self.checkedNodes) != JSON.stringify(self.tree_checked_keys)) {
            console.log("11111111111111111111");
            isDisabled = false;
          } else {
            console.log("22222222222222222222");
            isDisabled = true;
          }
        }
      }
      self.isDisabled = isDisabled;
      console.log(self.tags);
      console.log(self.checkedNodes);
    },
    //  下一步
    lvNextStepEvent() {
      console.log('lvNextStepEvent');
      self.active = '1';
    },
    //  上一步
    lvLastStepEvent() {
      console.log('lvLastStepEvent');
      self.active = '0';
    },
    //  标签树提交按钮事件
    doSubmitData(data) {
      console.log('return from selector', data);
      if (self.actionType == 0) { //新增
        let addParam = {
          group_name: self.inputText,
          company: self.commonParam.company,
          labels: JSON.stringify(data)
        };
        self.addGroupReq(addParam);
      } else {  //编辑
        var name = null;
        if (self.lastRadioSelectObj.groupText) {
          name = self.lastRadioSelectObj.groupText;
        } else {
          name = self.initRadioVal;
        }
        let updateParam = {
          new_group_name: self.currentInputText,
          old_group_name: name,
          company: self.commonParam.company,
          labels: JSON.stringify(data)
        }
        self.updateGroupReq(updateParam);
      }

    },
    //  关闭标签抽屉
    lvClose(e) {
      if (e && e.target.id === "lv-pop-up") {
        console.log("lvClose", e);
        self.cv_side = false;
        self.lv_side = false;
        self.isDisabled = true;
        self.tree_checked_keys = [];
        self.currentInputText = null;
        self.checkedNodes = [];
        self.active = '0';
        self.initData();
      }
    },
    //  通过取消按钮关闭标签抽屉
    lvCloseEvent() {
      console.log('lvCloseEvent');
      self.cv_side = false;
      self.lv_side = false;
      self.isDisabled = true;
      self.tree_checked_keys = [];
      self.currentInputText = null;
      self.checkedNodes = [];
      self.active = '0';
      self.initData();
    },

    //  显示指标变化抽屉按钮
    openChangeView() {
      console.log("showChange()");
      self.cv_side = true;
      self.getComputeReq(self.requestData);
    },
    //  关闭指标变化分析抽屉
    cvClose(e) {
      console.log("cvClose", e);
      if (e && e.target.id === "cv-pop-up") {
        console.log("zhangxf", e);
        self.cv_side = false;
        self.lv_side = false;
      }
    },
    //  通过取消按钮关闭指标变化分析抽屉
    cvCloseEvent() {
      self.cv_side = false;
      self.lv_side = false;
    },

    //  最终全页面提交
    validate() {
      self.commonParam.labels = self.tagArr;
      let mess = null;
      if (
        !self.commonParam.company ||
        !self.commonParam.type ||
        !self.commonParam.year ||
        !self.commonParam.number ||
        self.commonParam.labels == "[]" ||
        self.commonParam.labels == [] ||
        self.commonParam.labels.length <= 0 ||
        !self.commonParam.labels
      ) {
        mess = '请完成配置后再提交';
        self.$warnMessage(mess);
        return;
      }
      console.log("validate", self.commonParam);
      self.commonParam.labels = JSON.stringify(self.tagArr);
      self.$router.push({
        path: "/preview",
        query: {
          commonParam: self.commonParam
        }
      });
      let historyParam = JSON.stringify(self.commonParam);
      let historyRadioName = null;
      if (self.historyRadioObj.name) {
        historyRadioName = self.historyRadioObj.name;
      } else {
        historyRadioName = self.defaultRadioName;
      }
      sessionStorage.setItem("historyParam", historyParam);
      sessionStorage.setItem("historyRadioName", historyRadioName);
    },
  },
  destroyed() {
    self.$closeMessage();
  }
};

</script>

<style>
  @import './css/setting.css';
</style>
